package com.zyc.webtest.service;

import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;
import java.util.Optional;

/**
 * 类名称：BaseService<br>
 * 类描述：对Spring-Data-JPA Dao的简单封装，Service实现类可从该类继承<br>
 *
 * @param <T>  实体
 * @param <ID> 主键
 * @version v1.0
 */
public interface BaseService<T, ID extends Serializable> {

    public abstract JpaRepository<T, ID> getDao();

    public Optional<T> save(T t);

    public void save(List<T> tList);

    public void delete(ID id);

    public void delete(T t);

    public void delete(List<T> t);

    public void delete(ID[] t);

    @Transactional(readOnly = true)
    public Optional<T> findById(ID id);

    @Transactional(readOnly = true)
    public Optional<List<T>> findAll();

    @Transactional(readOnly = true)
    public Optional<List<T>> findAll(Sort sort);
}
